//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public class OfPieChart : PieChartBase
    {
        private readonly ObservableCollection<ChartLines> chartLines = new ObservableCollection<ChartLines>();
        private int customSplit;
        private int gapWidth = 150;
        private OfPieType ofPieType;
        private int secondPieSize = 75;
        private double splitPosition;
        private SplitType splitType;

        public OfPieType OfPieType
        {
            get { return ofPieType; }
            set { ofPieType = value; }
        }

        public int GapWidth
        {
            get { return gapWidth; }
            set { gapWidth = value; }
        }

        public SplitType SplitType
        {
            get { return splitType; }
            set { splitType = value; }
        }

        public double SplitPosition
        {
            get { return splitPosition; }
            set { splitPosition = value; }
        }

        public int CustomSplit
        {
            get { return customSplit; }
            set { customSplit = value; }
        }

        public int SecondPieSize
        {
            get { return secondPieSize; }
            set { secondPieSize = value; }
        }

        public ObservableCollection<ChartLines> ChartLines
        {
            get { return chartLines; }
        }


        protected override void VerifyAxes()
        {
            Debug.WriteLine("todo //\\" + GetType());
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("ofPieChart"))
            {
                OfPieType = c.ReadElementEnumAttribute<OfPieType>("ofPieType");
                ReadXmlBase(c);
                GapWidth = c.ReadOptionalElementIntegerAttribute("gapWidth", 150);
                SplitType = c.ReadOptionalElementEnumAttribute("splitType", SplitType.Position); //\\?
                SplitPosition = c.ReadOptionalElementDoubleAttribute("splitPos", 0);
                CustomSplit = c.ReadOptionalElementIntegerAttribute("custSplit", 0);
                SecondPieSize = c.ReadOptionalElementIntegerAttribute("secondPieSize", 75);
                while (c.ReaderLocalName == "serLines")
                {
                    ChartLines.Add(c.ReadElementAs<ChartLines>("serLines"));
                }
                Extension = c.ReadOptionalElement<ExtensionElement>("extLst");
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("ofPieChart"))
            {
                c.WriteElementEnumAttribute("ofPieType", OfPieType);
                WriteXmlBase(c);
                c.WriteOptionalElementIntegerAttribute("gapWidth", GapWidth, 150);
                c.WriteOptionalElementEnumAttribute("splitType", SplitType, SplitType.Position); //\\?
                c.WriteOptionalElementDoubleAttribute("splitPos", "val", SplitPosition, 0);
                c.WriteOptionalElementDoubleAttribute("custSplit", "val", CustomSplit, 0);
                c.WriteOptionalElementIntegerAttribute("secondPieSize", SecondPieSize, 75);
                foreach (ChartLines l in ChartLines)
                    c.WriteElementAs(l, "serLines");
                c.WriteOptionalElement(Extension);
            }
        }

        internal override IEnumerable<Axis> GetAxes()
        {
            yield break;
        }
    }
}